

<!DOCTYPE html>
<html>

<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>flv.js demo</title>
    <script src="/assets/libs/jquery/jquery.min.js"></script>
    <script  src="/flv.js"></script>
</head>
<body
<div style='display: block;'>
                           <video width="100%" height="100%"   x-webkit-airplay="allow" name="videoElement" id="videoElement" class=" video-js vjs-default-skin " x5-video-player-type="h5" x5-video-player-fullscreen="false"  x-webkit-airplay="allow" controls="" poster="img/poster.jpg"  x5-playsinline=""
                                 playsinline="" webkit-playsinline="" >
                                Your browser is too old which doesn't support HTML5 video.
                               </video>
                               </div>

<body>
<script>
var checkBoxFields = ['isLive', 'withCredentials', 'hasAudio', 'hasVideo'];

var mediaDataSource = {
                                type: 'flv',
                                isLive: true,
                                withCredentials : false,//一定要带上这个,否则会报跨域异常
                                hasAudio : false,
                                hasVideo : true,
                                cors : true,
                            };
$(function(){

mediaDataSource['url'] = 'http://47.92.196.10:8080/live/1.flv';
 console.log('MediaDataSource', mediaDataSource);
                            flv_load_mds(mediaDataSource,document.getElementsByName("videoElement")[0],i);
});
function flv_load_mds(mediaDataSource,element,i) {
        element.addEventListener('progress', function() {
            var range = 0;
            var bf = this.buffered;
            var time = this.currentTime;

            while(!(bf.start(range) <= time && time <= bf.end(range))) {
                range += 1;
            }
            this.currentTime = this.buffered.end(range) - 0.01;
        });
        if (typeof players['flvPlayer'+i] !== "undefined") {
            console.log("undefined");
            if (players['flvPlayer'+i] != null) {
                players['flvPlayer'+i].unload();
                players['flvPlayer'+i].detachMediaElement();
                players['flvPlayer'+i].destroy();
                player = null;
            }
        }
        players['flvPlayer'+i] = flvjs.createPlayer(mediaDataSource, {
            enableWorker: false,
            controls:true,
            //lazyLoadMaxDuration: 3 * 60,
            autoplay:false,
            seekType: 'range',
            enableStashBuffer: false,
            stashInitialSize: 128,//减少首桢显示等待时长
        });
        players['flvPlayer'+i].attachMediaElement(element);
        players['flvPlayer'+i].load();
        console.log("加载");
        // players['flvPlayer'+i].on(flvjs.Events.LOADING_COMPLETE,function () {
        //     alert("error comming");
        //     //players['flvPlayer'+i].pause();
        // });
        //debugger;
         players['flvPlayer'+i].play();

}

</script>
</html>